package com.xizi.SynchronizedTest;

public class Thread22 implements Runnable {
    //共享资源(临界资源)
    static int i = 0;

    @Override
    public void run() {
        for (int j = 0; j < 10000; j++) {
            synchronized (Thread22.class) {
                i++;
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread22 t = new Thread22();
        Thread t1 = new Thread(t);
        Thread t2 = new Thread(t);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
    /**
     * 输出结果:
     * 20000
     */
}
